package org.breathe.server.handler;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import lombok.extern.slf4j.Slf4j;
import org.breathe.protocal.Resp;

/**
 * @author: breathe
 * @createTime: 2025-05-12
 */
@Slf4j
public class RespEncoder extends MessageToByteEncoder<Resp> {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, Resp resp, ByteBuf buffer) throws Exception {
        try {
            resp.encode(resp, buffer);
        } catch (Exception e) {
            log.error("encode error");
            channelHandlerContext.channel().close();
        }
    }
}
